<script src="/js/vendor/kendo/kendo.dataviz.min.js"></script>
<link rel="stylesheet" href="<?=baseinfo?>/js/vendor/kendo/kendo.dataviz.min.css" />
<script>
var tabcheck=1;
var laststatus=1;
function statereportdata(tabcheckdata)
{
$('.checkreporttab').removeClass('tgFilStat');
$('#tabstate-'+tabcheckdata).addClass('tgFilStat');
tabcheck=tabcheckdata;
createreport(laststatus);
}
function exportdataset()
{
var startdateset=$('.startdateset').val();
var enddateset=$('.enddateset').val();
location.href=serviceinfo+'getstatposdata?status='+laststatus+'&startdate='+startdateset+'&enddate='+enddateset+'&output=1&nojson=1';

}
function updateoriginalprice(opriceid)
{
if($('#pricecheck-'+opriceid).val()!='')
{
$.post(serviceinfo+'updateoriginalprice', { opriceid:opriceid,oprice:$('#pricecheck-'+opriceid).val()}, function(data) { 

$('.micPopPOS.savemicOrdCp').fadeIn();
setTimeout('$( ".micPopPOS.savemicOrdCp" ).fadeOut();',2000);

});

}else
{


}


}
function createreport(status)
{
laststatus=status;
if(tabcheck==1)
{
var startdateset=$('.startdateset').val();
var enddateset=$('.enddateset').val();
$.get(serviceinfo+'getstatpos', { status:status,startdate:startdateset,enddate:enddateset}, function(data) { 


$('.benefitclass .fs18').html(data.data.benefit);
$('.totalorderclass .fs18').html(data.data.countorder);
$('.totalsoldclass .fs18').html(data.data.countitemsold);
$('.totalpromotionclass .fs18').html(data.data.countpromotion);

var code='';
$('.wrpSecStat.clearfix').html('');

$.each( data.data.stat, function( key, value ) {
code='';
if(value.data.length)
{
code = '<div class="secStat clBd2 bdFull">\n';
code += '<div class="hdSecStat clBd2 bdBtm clBg1">\n';
code += '<span class="clTxtPOSB fs03">'+value.name+'</span>\n';
code += '</div>\n';
code += '<div class="grpSecStat '+key+'classset">\n';
code += '</div>\n';
code += '<div class="bdSecStat">\n';
code += '<div class="bdLstStat">\n';

var irow=1;
$.each( value.data, function( key2, value2) {

code += '<div class="lstStat fs04 clearfix">\n';

code += '<div class="numLstStat">\n';
code += '<span class="sp sp9"><em>'+irow+'.</em></span>\n';
code += '</div>\n';

code += '<div class="nameLstStat">\n';
code += '<span class="cutTxt">'+value2.title+'</span>\n';
code += '</div>\n';

code += '<div class="amtLstStat">\n';
code += '<span>'+value2.show+'</span>\n';
code += '</div>\n';

code += '<div class="pcLstStat">\n';
code += '<span>'+value2.percent+'</span>\n';
code += '</div>\n';

code += '</div>\n';
irow++;
});


code += '</div>\n';
code += '</div>\n';
code += '</div>';
}

$('.wrpSecStat.clearfix').append(code);
createChart(value.data,'.'+key+'classset');

});



});
}else
{
var startdateset=$('.startdateset').val();
var enddateset=$('.enddateset').val();
$.get(serviceinfo+'getstatposdata', { status:status,startdate:startdateset,enddate:enddateset}, function(data) { 


$('#tabset2').html(data.table);




});




}

$('.wrprStatLst').hide();
$('#tabset'+tabcheck).show();



}
$( ".startdateset" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( ".enddateset" ).datepicker( "option", "minDate", selectedDate );
}
}); 
$( ".enddateset" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( ".startdateset" ).datepicker( "option", "maxDate", selectedDate );
}
}); 
function createChart(data,div) {

                //    $(div).kendoChart({
//                        title: {
//                            position: "bottom",
//                            text: ""
//                        },
//                        legend: {
//                            visible: false
//                        },
//                        seriesDefaults: {
//                            labels: {
//                                visible: true,
//                                background: "transparent",
//                                template: "#= category #: #= value#%",
//                                font: "10px sans-serif"
//                            }
//                        },
//                        series: [{
//                            type: "pie",
//                            startAngle: 90,
//                             size: 50,
//                            data: data
//                        }],
//                        tooltip: {
//                            visible: true,
//                            format: "#= category # - #= kendo.format('{0:P}', percentage) #"
//                        }
//                    });
                    
                    
                    
                    $(div).kendoChart({
                       
                        legend: {
                           position: "top"
                        },
                        seriesDefaults: {
                            labels: {
                                template: "#= category # - #= value #%",
                                position: "outsideEnd",
                                visible: true,
                                background: "transparent"
                            }
                        },
                        series: [{
                            type: "pie",
                            data: data
                        }],
                        tooltip: {
                            visible: true,
                            template: "#= category # - #= value #%"
                        }
                    });
                }
createreport(1);


</script>